package com.simba.server.commands.impl.fetch;

import java.sql.ResultSet;
import java.util.HashMap;
import java.util.Map;

import com.simba.common.command.ICommand;
import com.simba.common.database.DbOperator;

public class FetchBasicConfigCmd implements ICommand
{
	public static final String NAME = "FetchBasicConfigCmd";
	private final Map<String, String> retMap;
	String sql = "select * from tt_basic_config;";

	public FetchBasicConfigCmd(Map<String, String> resultMap)
	{
		this.retMap = resultMap;
	}

	@Override
	public String getName()
	{
		return FetchBasicConfigCmd.NAME;
	}

	@Override
	public Boolean run(Object params)
	{
		Boolean ret = false;

		if (!(params instanceof DbOperator))
		{
			return ret;
		}

		try
		{
			DbOperator dbOperator = (DbOperator) params;

			dbOperator.prepareStatement(this.sql);
			ResultSet rs = dbOperator.executeQuery();

			while (rs.next())
			{
				String key = rs.getString("basicKey");
				String value = rs.getString("basicValue");

				this.retMap.put(key, value);
			}

			ret = true;
		}
		catch (Exception ex)
		{
			ret = false;
		}

		return ret;
	}

}
